#! /usr/bin/env python
# -*- coding: utf-8 -*-

from playwright.sync_api import Page
from ui_automation_test.common.base_page import BasePage
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.checkInspectTask.loc_check_inspect_task_search import LocSearchCheckInspectTask
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.checkInspectTask.loc_check_inspect_task_view import LocViewCheckInspectTask
from ui_automation_test.common.logger import logger


class CheckInspectTask(BasePage):   

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('双重预防机制')
        self.switch_menu('隐患排查任务管理')
        self.switch_menu('隐患排查巡检任务')       
    
    def search_check_inspect_task(self, company, object_name, unit_name, inspect_status):
        """
        查询隐患排查巡检任务
        :param company: 所属企业
        :param object_name: 所属风险分析对象
        :param unit_name: 所属风险分析单元        
        :param inspect_status: 排查状态
        """
        logger.info('开始隐患排查巡检任务查询')
        if company:
            logger.info(f'选择被排查企业: {company}')
            self.select(LocSearchCheckInspectTask.loc_company_select, company)
        if object_name:
            logger.info(f'选择排查风险对象: {object_name}')
            self.select(LocSearchCheckInspectTask.loc_object_select, object_name)
        if unit_name:
            logger.info(f'选择排查风险单元: {unit_name}')
            self.select(LocSearchCheckInspectTask.loc_unit_name_select, unit_name)
        if inspect_status == '待排查':
            logger.info(f'选择排查状态: {inspect_status}')
            self.check_complex(LocSearchCheckInspectTask.loc_inspect_status, '待排查')
        elif inspect_status == '已排查':
            logger.info(f'选择排查状态: {inspect_status}')
            self.check_complex(LocSearchCheckInspectTask.loc_inspect_status, '已排查')
        elif inspect_status == '逾期未排查':
            logger.info(f'选择排查状态: {inspect_status}')
            self.check_complex(LocSearchCheckInspectTask.loc_inspect_status, '逾期未排查')
        elif inspect_status == '逾期未完成':
            logger.info(f'选择排查状态: {inspect_status}')
            self.check_complex(LocSearchCheckInspectTask.loc_inspect_status, '逾期未完成')
        elif inspect_status == '全部':
            logger.info(f'选择排查状态: {inspect_status}')
            self.check_complex(LocSearchCheckInspectTask.loc_inspect_status, '全部')
        logger.info('点击查询按钮')
        self.click(LocSearchCheckInspectTask.loc_search_button)
        self.page.wait_for_timeout(1000)

    def view_check_inspect_task(self, company, object_name, unit_name, inspect_status):
        """
        查看隐患排查巡检任务详情
        :param company: 所属企业
        :param object_name: 所属风险分析对象
        :param unit_name: 所属风险分析单元
        :param inspect_status: 排查状态
        """
        logger.info('开始隐患排查巡检任务查看')
        # 查询隐患排查巡检任务
        self.search_check_inspect_task(company, object_name, unit_name, inspect_status)
        self.page.wait_for_timeout(1000)
        logger.info('点击查看按钮')
        self.click(LocViewCheckInspectTask.loc_view_button)
        logger.info('查看隐患排查巡检任务详情')
        self.page.wait_for_timeout(6000)